package com.chenchao.method;

import java.util.function.Supplier;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/4 14:57
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.method.Test03.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * Supplier接口
 */
public class Test03 {
    public static void main(String[] args) {
        int[] ints = new int[]{1,2,5,7,9};
        /*lambda表达式可以引用外部变量，不了修改外部变量*/
        int maxValue=getMax(()->{
            int max=ints[0];
            for (int i = 1; i < ints.length; i++) {
                if(max<ints[i]){
                    max=ints[i];
                }
            }
            return max;
        });
        System.out.println(maxValue);
    }
    public static Integer getMax(Supplier<Integer> supplier){
        return  supplier.get();
    }
}
